package com.oauth.google.client.ui.orkut;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.oauth.google.client.beans.orkut.OrkutBirthday;
import com.oauth.google.client.beans.orkut.OrkutScrap;
import com.oauth.google.client.beans.orkut.OrkutUser;

public class ConnectionPanel extends Composite {

	private static ConnectionPanelUiBinder uiBinder = GWT
			.create(ConnectionPanelUiBinder.class);

	interface ConnectionPanelUiBinder extends UiBinder<HorizontalPanel, ConnectionPanel> {
	}

	@UiField
	HorizontalPanel hPanel1;

	@UiField
	HTMLPanel hPanel2AlignLeft;

	@UiField
	Image profileImage;

	@UiField
	Label name;

	@UiField
	Label status;

	@UiField
	Label birthday;

	@UiField
	Label scrap;
	
	OrkutUser mUser;

	public ConnectionPanel() {
		initWidget(uiBinder.createAndBindUi(this));
		hPanel1.setCellHorizontalAlignment(profileImage,
				VerticalPanel.ALIGN_LEFT);
		hPanel1.setCellHorizontalAlignment(hPanel2AlignLeft,
				VerticalPanel.ALIGN_LEFT);
	}

	public ConnectionPanel(OrkutUser user) {
		mUser = user;
		initWidget(uiBinder.createAndBindUi(this));
		hPanel1.setCellHorizontalAlignment(profileImage,
				VerticalPanel.ALIGN_LEFT);
		hPanel1.setCellHorizontalAlignment(hPanel2AlignLeft,
				VerticalPanel.ALIGN_LEFT);
	
		init();
	}

	public ConnectionPanel(OrkutBirthday pUser) {
		mUser = pUser.getUser();
		initWidget(uiBinder.createAndBindUi(this));
		hPanel1.setCellHorizontalAlignment(profileImage,
				VerticalPanel.ALIGN_LEFT);
		hPanel1.setCellHorizontalAlignment(hPanel2AlignLeft,
				VerticalPanel.ALIGN_LEFT);
		birthday.setVisible(true);
		birthday.setText(pUser.getDay()+"/"+pUser.getMonth());
		init();
	}

	public ConnectionPanel(OrkutScrap pUser) {
		mUser = pUser.getUser();
		initWidget(uiBinder.createAndBindUi(this));
		hPanel1.setCellHorizontalAlignment(profileImage,
				VerticalPanel.ALIGN_LEFT);
		hPanel1.setCellHorizontalAlignment(hPanel2AlignLeft,
				VerticalPanel.ALIGN_LEFT);
		scrap.setVisible(true);
		status.setVisible(false);
		birthday.setVisible(false);
		scrap.setText(pUser.getBody());
		init();
	}

	public void setUser(OrkutUser user) {
		mUser = user;
		init();
	}

	public void init() {
		profileImage.setUrl(mUser.getThumbNailUrl());
		status.setText(mUser.getStatus());
		name.setText(mUser.getDisplayName());
	}
	
	public void setSpacing(int spacing){
		hPanel1.setSpacing(spacing);
	}
	
	public void setWidth(String width){
		hPanel1.setWidth(width);
	}
}
